<?php
include('../../include/functions.inc.php');
$idFactura = getParam("id");
$rsFac = $db->query_select("cllg_factura", "ID=" . $idFactura);
$rsFacDet = $db->query_select("cllg_factura_detalle", "FK_FACTURA=" . $idFactura);
$rsFac = $rsFac[0];
$status = $rsFac["STATUS"];
$rsFac["NUMERO"] = isset($rsFac["NUMERO"]) ? intval($rsFac["NUMERO"]) : 0;
$rsFac["SERIE"] = isset($rsFac["SERIE"]) ? $rsFac["SERIE"] : '';
$rsFac["FECHA"] = isset($rsFac["FECHA"]) ? date_format(date_create_from_format('Y-m-d', $rsFac["FECHA"]), 'd/m/Y') : '';
$rsFac["NIT"] = isset($rsFac["NIT"]) ? $rsFac["NIT"] : '';
$rsFac["NOMBRE"] = isset($rsFac["NOMBRE"]) ? $rsFac["NOMBRE"] : '';
$rsFac["DIRECCION"] = isset($rsFac["DIRECCION"]) ? $rsFac["DIRECCION"] : '';
$rsFac["FK_STUDENT"] = isset($rsFac["FK_STUDENT"]) ? intval($rsFac["FK_STUDENT"]) : 0;
$rsFac["MORA"] = isset($rsFac["MORA"]) ? doubleval($rsFac["MORA"]) : 0;
$rsFac["DOLARES"] = isset($rsFac["DOLARES"]) ? floatval($rsFac["DOLARES"]) : 0;
$rsFac["TASA_CAMBIO"] = isset($rsFac["TASA_CAMBIO"]) ? doubleval($rsFac["TASA_CAMBIO"]) : 0;
$rsFac["EFECTIVO"] = isset($rsFac["EFECTIVO"]) ? doubleval($rsFac["EFECTIVO"]) : 0;
$rsFac["DEPOSITO"] = isset($rsFac["DEPOSITO"]) ? doubleval($rsFac["DEPOSITO"]) : 0;
$rsFac["CHEQUE"] = isset($rsFac["CHEQUE"]) ? doubleval($rsFac["CHEQUE"]) : 0;
$rsFac["TOTAL"] = isset($rsFac["TOTAL"]) ? floatval($rsFac["TOTAL"]) : 0;
$rsFac["SUBTOTAL"] = isset($rsFac["SUBTOTAL"]) ? floatval($rsFac["SUBTOTAL"]) : 0;
$rsFac["IVA"] = isset($rsFac["IVA"]) ? floatval($rsFac["IVA"]) : 0;

$cStatus = "ACTIVA";
switch ($status) {
    case 0:
        $cStatus = "ANULADA";
        break;
    case 2:
        $cStatus = "PENDIENTE PAGO";
        break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Visualidor </title>

        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <script src="lib.js" type="text/javascript"></script>
    </head>
    <body>
        <form id="factura" name="factura" method="post" action="view.php">
            <input type="hidden" value="change" name="operation" id="operation">
                <input type="hidden" value="<?= $idFactura ?>" name="id" id="id">
                    <input type="hidden" value="" name="value" id="value">
                        <table width="505" border="0" cellpadding="0" cellspacing="0" class="">
                            <tr>
                                <th width="295" scope="col"><legend>Datos de Factura</legend></th>
                                <th width="217" align="right" scope="col"><legend>Estado:<?= $cStatus ?></legend></th>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <table width="100%" border="0" cellspacing="0" class="table table-striped table-bordered" cellpadding="0">
                                        <tr>
                                            <td width="16%"><strong>Numero:</strong></td>
                                            <td width="34%"><?= $rsFac["NUMERO"] ?></td>
                                            <td width="18%"><strong>Serie:</strong></td>
                                            <td width="32%"><?= $rsFac["SERIE"] ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>Fecha:</strong></td>
                                            <td><?= $rsFac["FECHA"] ?></td>
                                            <td><strong>Nit:</strong></td>
                                            <td><?= $rsFac["NIT"] ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>Nombre:</strong></td>
                                            <td><?= $rsFac["NOMBRE"] ?></td>
                                            <td><strong>Direccion:</strong></td>
                                            <td><?= $rsFac["DIRECCION"] ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>No. Carnet:</strong></td>
                                            <td><?= $rsFac["FK_STUDENT"] ?></td>
                                            <td><strong>Mora:</strong></td>
                                            <td><?= number_format($rsFac["MORA"], 2) ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>Dolares:</strong></td>
                                            <td><?= number_format(floatval($rsFac["DOLARES"]), 2) ?></td>
                                            <td><strong>Tasa Cambio:</strong></td>
                                            <td><?= number_format($rsFac["TASA_CAMBIO"], 2) ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>Efectivo:</strong></td>
                                            <td><?= number_format(floatval($rsFac["EFECTIVO"]), 2) ?></td>
                                            <td><strong>Deposito:</strong></td>
                                            <td><?= number_format($rsFac["DEPOSITO"], 2) ?></td>
                                        </tr>
                                        <tr>
                                            <td><strong>Cheque:</strong></td>
                                            <td><?= number_format($rsFac["CHEQUE"], 2) ?></td>
                                            <td><strong>Total:</strong></td>
                                            <td><?php print number_format($rsFac["TOTAL"], 2); ?></td>
                                            <?php
                                            if (empty($rsFac["FK_STUDENT"])) {
                                                ?>
                                                    <!--<td><?php print number_format($rsFac["SUBTOTAL"] + $rsFac["IVA"], 2); ?></td>-->
                                                <?php
                                            } else {
                                                ?>
                                                    <!--<td><?php print number_format($rsFac["SUBTOTAL"] + $rsFac["IVA"], 2); ?></td>-->
                                                <?php
                                            }
                                            ?>
                                        </tr>
                                        <tr>
                                            <td colspan="4"><div id="datacontainer" style="width:500px;">
                                                    <table width="100%" cellpadding="0" cellspacing="0" class="table table-striped table-bordered">
                                                        <thead>
                                                            <tr>
                                                                <th width="17%"  >Cantidad</th>
                                                                <th width="61%">Descripci&oacute;n</th>
                                                                <th width="22%" align="right">Subtotal</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?PHP foreach ($rsFacDet as $linea) { ?>
                                                                <tr class="line0">
                                                                    <td><?= $linea["CANTIDAD"] ?></td>
                                                                    <td><?= $linea["DESCRIPCION"] ?></td>
                                                                    <td align="right"><?= number_format($linea["SUBTOTAL"], 2) ?></td>
                                                                </tr>
                                                            <?php } ?>

                                                        </tbody>
                                                    </table>
                                                </div></td>
                                        </tr>
                                        <?php if (isEmpty(getParam("fromReport"))) { ?>
                                            <tr>
                                                <td colspan="4"><?php if ($status != 0) { ?>
                                                        <input name="cmdAnular" type="button" onclick="doChange(0);"
                                                               class="btn btn-info" id="cmdAnular" value="Anular" />
                                                        <input name="cmdPendientes" type="button" onclick="doChange(2);"
                                                               class="btn btn-info" id="cmdPendientes" value="Pendiente"
                                                               <?= $status == 2 ? 'disabled="disabled"' : '' ?> />
                                                           <?php } ?>
                                                </td>

                                            </tr>
                                        <?php } ?>
                                    </table></td>
                            </tr>
                        </table>
                        </form>
                        </body>
                        </html>